﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace Frame.Global
{
    public class uSQLCA : IDisposable
    {

        #region 连接和事务
        protected SqlConnection mSc;
        public SqlConnection SqlConn
        {
            get { return mSc; }
        }

        protected SqlTransaction mTr;
        public SqlTransaction SqlTran
        {
            get { return mTr; }
        }

        #endregion

        /// <summary>
        /// 构造函数
        /// </summary>
        public uSQLCA()
        {
            mSc = new SqlConnection(GlobalRunParms.PubdataConncetionString);
            mSc.Open();
            mTr = mSc.BeginTransaction();
        }

        /// <summary>
        /// 数据库通讯事务提交
        /// </summary>
        public void Commit()
        {
            try
            {
                this.mTr.Commit();
            }
            catch (Exception)
            {

                throw;
            }

        }

        /// <summary>
        /// 数据库通讯事务回滚
        /// </summary>
        public void Rollback()
        {
            try
            {
                this.mTr.Rollback();
            }
            catch (Exception)
            {

                throw;
            }

        }


        #region IDisposable 成员
        /// <summary>
        /// 释放对象
        /// </summary>
        public void Dispose()
        {
            mTr.Dispose();

            mSc.Close();
            mSc.Dispose();
        }

        #endregion
    }
}
